<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>订单列表</title>
    <link rel="stylesheet" href="../layui/css/layui.css"/>
    <script type="text/javascript" src="../layui/layui.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/x-layui.js" charset="utf-8"></script>
</head>
<body>
<table id="demo" lay-filter="demo" style="width: 50px;height: auto"></table>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script>
    layui.use('table', function () {
        var totalCount;
        var table = layui.table;
        var $ = layui.$;
        //监听工具条
        table.on('tool(demo)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    $.post("../deleteById1.do", {"id": data.id}, function (data) {
                        if (data.success) {
                            layer.msg(data.message, {icon: 1, time: 2000, offset: '100px'})
                            layer.close(index);
                            var limit = $(".layui-laypage-limits").find("option:selected").val();
                            totalCount = totalCount - 1;
                            if (totalCount % limit === 0) {
                                var yema = totalCount / limit;
                                layui.table.reload('demo', {page: {curr: yema}});
                            } else {
                                layui.table.reload('demo');
                            }
                        } else {
                            layer.msg(data.message, {icon: 2, time: 2000, anim: 6, offset: '100px'})
                            layer.close(index);
                            layui.table.reload('demo');
                        }
                    }, "json");
                    layer.close(index);
                });
            }
        });
        table.render({
            elem: '#demo'
            , height: 500
            , url: '../findAllOrder.do' //数据接口
            , page: true //开启分页
            , cellMinWidth: 80
            , limit: 5
            , limits: [5, 10, 15, 20]
            , title: '订单列表'
            , width: '1156'
            , done: function (res, curr, count) {
                totalCount = count;
            }
            , cols: [[
                {
                    field: 'orderNumber', title: '订单号', templet: function (d) {
                        return "<div><a href='javascript:void(0)' onclick='x_admin_show(\"订单详情\",\"orderInfo.html?orderNum=" + d.orderNumber + "\",500,350);' style='color: #3247ff'>" + d.orderNumber + "</a></div>";
                    }
                }
                , {
                    field: 'loginName', title: '顾客名', templet: function (d) {
                        return '<div>' + d.login.loginName + '</div>';
                    }
                }
                , {field: 'tableId', title: '桌号'}
                , {field: 'foodPrice', sort: true, title: '总价钱'}
                , {field: 'orderState', title: '状态'}
                , {field: 'date', title: '时间'}
                , {fixed: 'right', width: 165, align: 'center', toolbar: '#barDemo'}
            ]]

        });
    });
</script>
<script src="../js/mouse.js"></script>

</body>
</html>